package com.usian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.common.model.competition.CompetitionHistory;
import com.usian.mapper.CompetitionHistoryMapper;
import com.usian.service.CompetitionHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @projectName: 2210A-project1
 * @package: com.usian.service.impl
 * @className: CompetitionHistoryServiceImpl
 * @author: 莫洪维
 * @email: 1204315800@qq.com
 * @description: TODO
 * @date: 2023/8/29 16:56
 */
@Service
public class CompetitionHistoryServiceImpl extends ServiceImpl<CompetitionHistoryMapper, CompetitionHistory> implements CompetitionHistoryService {

    @Autowired(required = false)
    private CompetitionHistoryMapper historyMapper;

    @Override
    public List<CompetitionHistory> toHistory(CompetitionHistory competitionHistory) {
        //调用方法进行查询
        QueryWrapper<CompetitionHistory> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(CompetitionHistory::getPaperId,competitionHistory.getPaperId());
        wrapper.lambda().eq(CompetitionHistory::getCompetitionId,competitionHistory.getCompetitionId());
        wrapper.lambda().eq(CompetitionHistory::getMemberId,competitionHistory.getMemberId());
        List<CompetitionHistory> list = historyMapper.selectList(wrapper);
        return list;
    }

    @Override
    public Integer toHistoryNum(CompetitionHistory competitionHistory) {
        //调用方法进行查询
        QueryWrapper<CompetitionHistory> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(CompetitionHistory::getPaperId,competitionHistory.getPaperId());
        wrapper.lambda().eq(CompetitionHistory::getCompetitionId,competitionHistory.getCompetitionId());
        wrapper.lambda().eq(CompetitionHistory::getMemberId,competitionHistory.getMemberId());
        Integer num = historyMapper.selectCount(wrapper);
        return num;
    }
}
